package com.yuexun.dhdoctor.module.my.adapter;

import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.my.bean.MessageInfoBeanDate;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by work-jx on 2016/11/23.
 */
public class MessageAdapter extends KJAdapter<MessageInfoBeanDate> {

    boolean isDo;

    public void setDo(boolean aDo) {
        isDo = aDo;
        notifyDataSetChanged();
    }

    public MessageAdapter(AbsListView view, Collection<MessageInfoBeanDate> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder adapterHolder, final MessageInfoBeanDate messageInfoBeanDate, boolean b) {
//        adapterHolder.setText(R.id.item_message_time,messageInfoBeanDate.getCreateTime().substring(0,10));
        adapterHolder.setText(R.id.item_message_time,messageInfoBeanDate.getCreateTime());

        TextView title = (TextView) adapterHolder.getView(R.id.item_message_title);
        TextView content = (TextView) adapterHolder.getView(R.id.item_message_content);
        ImageView selectView = (ImageView) adapterHolder.getView(R.id.select_view);

        title.setText(Html.fromHtml(messageInfoBeanDate.getTitle().replace("＜", "<").replace("＞", ">")));
        content.setText(Html.fromHtml(messageInfoBeanDate.getContent().replace("＜", "<").replace("＞", ">")));

        if(messageInfoBeanDate.getState() == 0){
            title.setTextColor(ContextCompat.getColor(mCxt, R.color.txt_black1));
            content.setTextColor(ContextCompat.getColor(mCxt, R.color.txt_black1));
        }else{
            title.setTextColor(ContextCompat.getColor(mCxt, R.color.txt_black2));
            content.setTextColor(ContextCompat.getColor(mCxt, R.color.txt_black2));
        }

        if(isDo){
            selectView.setVisibility(View.VISIBLE);
        }else{
            selectView.setVisibility(View.GONE);
        }

        if(messageInfoBeanDate.isSelect()){
            selectView.setImageResource(R.drawable.add_member_checked);
        }else{
            selectView.setImageResource(R.drawable.add_member_unchecked);
        }

        selectView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(messageInfoBeanDate.isSelect()){
                    messageInfoBeanDate.setSelect(false);
                }else{
                    messageInfoBeanDate.setSelect(true);
                }
                notifyDataSetChanged();
            }
        });

    }

}
